package com.study.practice.controller;

import lombok.Data;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ClassInfo {
    static class Pet1<T> {
        public <V> V test(V a) {
            System.out.println("AA");
            return a;
        }
    }


    static class Pet extends ClassInfo {

    }

    static class Dog extends ClassInfo {
    }

    static class Cat extends ClassInfo {
    }

    public static void main(String[] args) {
        @Data
        class Dish {
            private int Calories;

            private String name;

            private String type;

            @Override
            public String toString() {
                return "Dish{" +
                        "Calories=" + Calories +
                        ", name='" + name + '\'' +
                        '}';
            }
        }
        List<Dish> menu = new ArrayList<>();
        final Comparator<Dish> dishComparator = Comparator.comparingInt(Dish::getCalories);
        final Optional<Dish> mostCaloriesDish = menu.stream().collect(Collectors.maxBy(dishComparator));
        final Integer totalCalories = menu.stream().collect(Collectors.summingInt(Dish::getCalories));
        final IntSummaryStatistics summaryStatistics = menu.stream().collect(Collectors.summarizingInt(Dish::getCalories));

        final String menuNames = menu.stream().map(Dish::getName).collect(Collectors.joining());
        menu.stream().collect(Collectors.toList());

        final Map<String, List<Dish>> dishesByType = menu.stream().collect(Collectors.groupingBy(Dish::getType));

        final Map<CaloricLevel, List<Dish>> caloricLevelListMap = menu.stream().collect(Collectors.groupingBy(dish -> {
            if (dish.getCalories() <= 400) {
                return CaloricLevel.DIET;
            } else if (dish.getCalories() <= 700) {
                return CaloricLevel.NORMAL;
            } else {
                return CaloricLevel.FAT;
            }
        }));

        final Map<String, Map<CaloricLevel, List<Dish>>> dishesMap1 = menu.stream().collect(Collectors.groupingBy(Dish::getType, Collectors.groupingBy(dish -> {
            if (dish.getCalories() <= 400) {
                return CaloricLevel.DIET;
            } else if (dish.getCalories() <= 700) {
                return CaloricLevel.NORMAL;
            } else {
                return CaloricLevel.FAT;
            }
        })));

        final Map<String, Long> dishesMap2 = menu.stream().collect(Collectors.groupingBy(Dish::getType, Collectors.counting()));



    }



    public enum CaloricLevel {DIET, NORMAL, FAT}

}
